const path = require("path");
const { sep } = path;
module.exports = (app) => {
  console.log("config");
  const configPath = path.resolve(app.baseDir, `.${sep}config`);
  console.log(configPath);
  let defaultConfig = {};
  try {
    defaultConfig = require(path.resolve(
      configPath,
      `.${sep}config.default.js`
    ));
  } catch (e) {
    console.log("default config not found");
  }
  let envConfig = {};
  try {
    let env = app.env;
    if (env.isLocal()) {
      envConfig = require(path.resolve(configPath, `.${sep}config.local.js`));
    } else if (env.isBeta()) {
      envConfig = require(path.resolve(configPath, `.${sep}config.beta.js`));
    } else if (env.isProduction()) {
      envConfig = require(path.resolve(configPath, `.${sep}config.prod.js`));
    }
  } catch (e) {
    console.log(`[exception] there is no env.config file`);
  }
  app.config = Object.assign({},defaultConfig,envConfig);
};
